local function send_post(path, params) 
    if (GET == ngx.req.get_method())
    then 
         m = ngx.HTTP_GET;
    elseif (POST == ngx.req.get_method()) then
         m = ngx.HTTP_POST;
    end

    local response = ngx.location.capture(path, {
        -- method = ngx.HTTP_POST,  
        method = m, 
        args = params  
    });
    -- 目标路径不存在，无法响应客户端
    if not response then
        ngx.exit(404);
    end
    -- 只要有响应，不管是200还是5xx状态，直接return
    return response.body;
end




-- 导出函数
-- local http = {
--     send_post = send_post
-- }
-- return http;


local function get(path, params) 
    local response = ngx.location.capture(path, {
        method = ngx.HTTP_GET,   
        args = params 
    });
    -- 目标路径不存在，无法响应客户端
    if not response then
        ngx.exit(404);
    end
    -- 只要有响应，不管是200还是5xx状态，直接return
    return response.body;
end

local function post(path, params, body) 
    local response = ngx.location.capture(path, {
        method = ngx.HTTP_POST,   
        args = params,
        body = body
    });
    -- 目标路径不存在，无法响应客户端
    if not response then
        ngx.exit(404);
    end
    -- 只要有响应，不管是200还是5xx状态，直接return
    return response.body;
end

-- 导出函数
local http = {
    post = post,
    get = get,
    send_post = send_post
}
return http;